<template>
  <div id="dialogSort">
    <el-dialog
      class="about-set"
      title="修改排序"
      :visible.sync="sortData.isShow"
      width="420px"
      :before-close="labelHandleClose"
    >
      <div class="form-box">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="80px"
          class="demo-ruleForm"
          @submit.native.prevent
        >
          <el-form-item label="显示排序" prop="sort">
            <el-input-number
              v-model="ruleForm.sort"
              size="mini"
              controls-position="right"
              :max="99999"
              :min="1"
            ></el-input-number>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" plain @click="cancelLabel">取 消</el-button>
        <el-button
          type="success"
          :loading="loading"
          @click="confirmLabel('ruleForm')"
          >确认</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script> 
import {
  sortActive,
} from '@/api/flowerActive/flowerActiveList/index'
// 接口
export default {
  name: 'DialogSort',
  msg: '鲜花活动排序-排序弹窗',
  props: ['sortData'],
  data() {
    //校验排序
    var valiSort = (rule, value, callback) => {
      if (!value) {
        callback(new Error('数字不能为空'))
      }
      callback()
    }
    return {
      loading: false,
      id: null,
      ruleForm: {
        sort: ''
      },
      rules: {
        sort: [{ validator: valiSort, trigger: 'blur' }]
      }
    }
  },
  mounted() {
    this.id = this.sortData.id
    this.total = this.sortData.total
    this.ruleForm.sort = this.sortData.sort
  },
  methods: {
    /* 确认提交 */
    confirmLabel(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.subForm()
        } else {
          return false
        }
      })
    },
    /* 确认提交 */
    subForm() {
      // return true
      // this.loading = true
      // let params = { newOrder: this.ruleForm.sort, isQueryString: true }
      // if (this.ruleForm.sort > this.total) {
      //   this.$message.error('置顶序号不能大于当前总数')
      //   this.loading = false
      // } else {
       
      // }
       let params = {
        sort: this.ruleForm.sort
      }
       sortActive(
          this.id,
          params,
          (response) => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.loading = false
            this.$emit('refresh')
            this.cancelLabel()
          },
          (response) => {
            this.loading = false
            this.$message({
              message: response.message,
              type: 'warning'
            })
          }
        )
    },
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.loading = false
      this.id = null
      this.sortData.params = null
      this.sortData.isShow = false
    }
  }
}
</script>

<style lang="less">
</style>
